package com.hypo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hypo.mapper.UserMapper;
import com.hypo.pojo.LoginInfo;
import com.hypo.pojo.User;
import com.hypo.service.UserService;
import com.hypo.untils.JwtUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    private final UserMapper userMapper;


    @Override
    public LoginInfo getToken(User userInfo) {
        //1.生成载荷
        HashMap<String, Object> claims = new HashMap<>();
        claims.put("id", userInfo.getId());
        claims.put("name", userInfo.getName());
        claims.put("username", userInfo.getUsername());
        //2.调用JwtUtils生成令牌
        String jwt = JwtUtils.generateJwt(claims);
        //3.返回LoginInfo数据
        return new LoginInfo(userInfo.getId(), userInfo.getName(), userInfo.getUsername(), jwt);
    }
}
